package io.gitee.icefairy.total_monitor.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import io.gitee.icefairy.total_monitor.model.RetObj;
import io.gitee.icefairy.total_monitor.service.MonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.erupt.upms.util.IpUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.TimeZone;

/**
 * 监控项目管理
 * Author:icefairy
 * Date:2021/12/13 0013
 **/
@RestController
@RequestMapping("/monitor")
public class MonitorController {
    @Autowired
    MonitorService ms;
    Log log = LogFactory.get();


    /**
     * 活跃一次
     * @param id
     * @param status 1=normal 0=error
     * @param extra
     * @param note
     * @return
     */
    @PostMapping("/active")
    public RetObj active(String id, int status, String extra, String note, HttpServletRequest req) {
        return ms.active(id,status,extra,note, IpUtil.getIpAddr(req));
    }

    /**
     *  获取所有组件状态
     * @return
     */
    @GetMapping("/list")
    public RetObj list(Pageable pa ){
        return ms.list(pa);
    }
//    public void test(){
//        TimeZone tz=TimeZone.getDefault();
//        System.out.println(tz.toZoneId().toString());
//    }
}
